package com.withoutwords.engine.social;

import java.io.Serializable;

import org.json.JSONException;
import org.json.JSONObject;

import com.withoutwords.engine.ConvertableJson;

public class SocialUser implements ConvertableJson,Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 5823844753601297309L;
	String SocialID;
	public String getSocialID() {
		return SocialID;
	}
	String Name;
	@Override
	public String toString() {
		return Name;
	}
	public String getName() {
		return Name;
	}
	public void setName(String name) {
		Name = name;
	}
	
	SocialNetwork network;
	@Override
	public JSONObject toJSON() {
		JSONObject obj = new JSONObject();
		try {
			obj.put("name", Name);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			obj.put("social_id", SocialID);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			if(network != null)
			obj.put("network", network.ordinal());
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return obj;
	}
	@Override
	public boolean fromJSON(JSONObject obj) {
		
		try {
			Name = obj.getString("name");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			//return false;
		}

		try
		{
			
			SocialID = obj.getString("social_id");
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			//return false;
		}

		try
		{
			network= SocialNetwork.values()[obj.getInt("network")];
			
			
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			//return false;
		}
		return true;
		
		
	}

}
